package cn.com.shopec.erp.system.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * 
 * @ClassName Role
 * @Description 角色表实体
 * @author chengui
 * @date 2013-5-29 下午5:02:14
 */
@Entity
@Table(name = "tbl_scm_role")
public class Role implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7507875186846035004L;
	
	/** 主键. */
	private String id;
	/** 角色名称. */
	private String roleName;
	/** 角色编码. */
	private String roleCode;
	/** 角色类型:1-平台，2-供应商. */
	private int roleType;
	/** 备注. */
	private String remark;
	/** 删除标识:0-已删除，1-未删除. */
	private int deleteFlag = 1;
	
	/** 用户. */
	private Set<User> users = new HashSet<User>();
	/** 权限. */
	private Set<Access> accesses = new HashSet<Access>();

	public Role() {
		super();
	}
	public Role(String id) {
		super();
		this.id = id;
	}
	public Role(String id, String roleName, String roleCode, int roleType,
			String remark, int deleteFlag, Set<User> users, Set<Access> accesses) {
		super();
		this.id = id;
		this.roleName = roleName;
		this.roleCode = roleCode;
		this.roleType = roleType;
		this.remark = remark;
		this.deleteFlag = deleteFlag;
		this.users = users;
		this.accesses = accesses;
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	@Column(name = "role_name")
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	@Column(name = "role_code")
	public String getRoleCode() {
		return roleCode;
	}
	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}
	@Column(name = "role_type")
	public int getRoleType() {
		return roleType;
	}
	public void setRoleType(int roleType) {
		this.roleType = roleType;
	}
	@Column(name = "remark")
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	@Column(name = "delete_flag")
	public int getDeleteFlag() {
		return deleteFlag;
	}
	public void setDeleteFlag(int deleteFlag) {
		this.deleteFlag = deleteFlag;
	}
	
	@ManyToMany(mappedBy = "roles")
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	@ManyToMany
	@JoinTable(name = "tbl_scm_role_access", 
	joinColumns = {@JoinColumn(name = "role_id")},
	inverseJoinColumns = {@JoinColumn(name = "access_id")})
	public Set<Access> getAccesses() {
		return accesses;
	}
	public void setAccesses(Set<Access> accesses) {
		this.accesses = accesses;
	}
	
}
